package com.tanhua.app.controller;

import com.tanhua.app.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    @PostMapping(value = "/contacts",name="添加好友")
    public ResponseEntity contacts(@RequestBody Map<String,String> map) throws IOException {
        Integer friendId =Integer.parseInt(map.get("userId"));
        System.out.println(friendId);
        return messagesService.addFriends(friendId);
    }

    @GetMapping(value = "/contacts",name="分页查询好友列表")
    public ResponseEntity findFriends(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize) throws IOException {

        System.out.println(page);
        System.out.println(pagesize);
        return messagesService.findFriends(page,pagesize);
    }



    @GetMapping(value = "/likes",name="点赞的用户列表")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize) throws IOException {

        return messagesService.findPage(page,pagesize,1);

    }

    @GetMapping(value = "/comments",name="评论的用户列表")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize) throws IOException {

        return messagesService.findPage(page,pagesize,2);
    }

    @GetMapping(value = "/loves",name="喜欢的用户列表")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize) throws IOException {

        return messagesService.findPage(page,pagesize,3);
    }



    
}
